home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16_Src.lha / Python16_Source / Include / longintrepr.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-03  |  1.7 KB  |  51 lines

  1. #ifndef Py_LONGINTREPR_H
  2. #define Py_LONGINTREPR_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6.  
  7. /* This is published for the benefit of "friend" marshal.c only. */
  8.  
  9. /* Parameters of the long integer representation.
  10.    These shouldn't have to be changed as C should guarantee that a short
  11.    contains at least 16 bits, but it's made changeable any way.
  12.    Note: 'digit' should be able to hold 2*MASK+1, and 'twodigits'
  13.    should be able to hold the intermediate results in 'mul'
  14.    (at most MASK << SHIFT).
  15.    Also, x_sub assumes that 'digit' is an unsigned type, and overflow
  16.    is handled by taking the result mod 2**N for some N > SHIFT.
  17.    And, at some places it is assumed that MASK fits in an int, as well. */
  18.  
  19. typedef unsigned short digit;
  20. typedef unsigned int wdigit; /* digit widened to parameter size */
  21. typedef unsigned long twodigits;
  22. typedef long stwodigits; /* signed variant of twodigits */
  23.  
  24. #define SHIFT    15
  25. #define BASE    ((digit)1 << SHIFT)
  26. #define MASK    ((int)(BASE - 1))
  27.  
  28. /* Long integer representation.
  29.    The absolute value of a number is equal to
  30.        SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)
  31.    Negative numbers are represented with ob_size < 0;
  32.    zero is represented by ob_size == 0.
  33.    In a normalized number, ob_digit[abs(ob_size)-1] (the most significant
  34.    digit) is never zero.  Also, in all cases, for all valid i,
  35.        0 <= ob_digit[i] <= MASK.
  36.    The allocation fuction takes care of allocating extra memory
  37.    so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available. */
  38.  
  39. struct _longobject {
  40.     PyObject_HEAD
  41.     int ob_size;
  42.     digit ob_digit[1];
  43. };
  44.  
  45. DL_IMPORT(PyLongObject *) _PyLong_New Py_PROTO((int));
  46.  
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. #endif /* !Py_LONGINTREPR_H */
  51.